<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<HEAD>
<meta name="GENERATOR" content="Microsoft&reg; HTML Help Workshop 4.1">
<Title>complex types</Title><link rel="STYLESHEET" type="text/css" href="styles.css">
</HEAD>
<BODY>
<h1>Complex Types using the Node and Nodes objects</h1>

Any non-trivial web service will require you to handle complex types. There are two basic approachs in pocketSOAP for
working with complex types, you can use serializers that map between SOAP complex types and objects within your system, 
or you can work with the node objects and collections directly. This section contains details on working with the Node
and Nodes objects, the advanced topics section details writing custom serializers.

<h2>Sample complex type</h2>

The Apache SOAP project includes a sample called the addressbook sample, in this it defines a complex type for a phone number
and a complex type for an address, which includes a phone number. Here's an example of an instance of the address type.

<pre class="sample">
&lt;address&gt;
	&lt;number&gt;100&lt;/number&gt;
	&lt;street&gt;Spear Street&lt;/street&gt;
	&lt;city&gt;San Francisco&lt;/city&gt;
	&lt;state&gt;CA&lt;/state&gt;
	&lt;zip&gt;94107&lt;/zip&gt;
	&lt;phone&gt;
		&lt;area&gt;415&lt;/area&gt;
		&lt;exchange&gt;343&lt;/exchange&gt;
		&lt;number&gt;3000&lt;/number&gt;
	&lt;/phone&gt;
&lt;/address&gt;
</pre>

<h2>Deserialization</h2>

In the absense of any deserializer registered to handle a particular complex type, pocketSOAP will deserialize the complex type using a
generic complex type deserializer. The generates a nested collection of Node objects, one per element. Once parsing is finished, the pocketSOAP
application can use the Nodes &amp; Value properties to access the tree of nodes. for example, we make a SOAP call, and this is the response

<pre class="sample">
&lt;s:Envelope xmlns:s=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
&lt;s:Body s:EncodingStyle=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot;&gt;
&lt;m:getAddressResponse xmlns:m=&quot;http://address.examples.org/schema/&quot;&gt;
&lt;address&gt;
	&lt;number&gt;100&lt;/number&gt;
	&lt;street&gt;Spear Street&lt;/street&gt;
	&lt;city&gt;San Francisco&lt;/city&gt;
	&lt;state&gt;CA&lt;/state&gt;
	&lt;zip&gt;94107&lt;/zip&gt;
	&lt;phone&gt;
		&lt;area&gt;415&lt;/area&gt;
		&lt;exchange&gt;343&lt;/exchange&gt;
		&lt;number&gt;3000&lt;/number&gt;
	&lt;/phone&gt;
&lt;/address&gt;
&lt;/m:getAddressResponse&gt;
&lt;/s:Body&gt;
&lt;/s:Envelope&gt;
</pre>

The following code will access the fields of the complex type returned.
<pre class="sample">
' Assuming env is a pocketSOAP Envelope object, and http is a transport object, and that we've sucessfully built and sent the request.

' parse the response
env.parse http

' address is the first child in the response parameters, so lets grab that first
dim adr
set adr = env.Parameters.Item(0).Value

' now we simply use the ItemByName function on the Nodes collection class to access each contained field
wscript.echo adr.Nodes.ItemByName("number").Value &amp; " " &amp; adr.Nodes.ItemByName("street").value
wscript.echo adr.Nodes.ItemByName("city").Value &amp; " " &amp adr.Nodes.ItemByName("state").value
wscript.echo adr.Nodes.ItemByName("zip").Value

' as phone is a nested complex type, we grab the phone node, then look at its children
dim ph
set ph = adr.Nopdes.ItemByName("phone")
wscript.echo ph.Nodes.ItemByName("area").value &amp; " " &amp; ph.Nodes.ItemByName("exchange").value &amp; " " &amp; ph.Nodes.ItemByName("number").value
</pre>

<h2>Serialization</h2>

Sending complex types works in the reverse manner, the application builds a nested set of node objects, which get serialized into the complex type
when serialize is called.
<pre class="sample">
dim env, adr, ph
set env = CreateObject("pocketSOAP.Envelope.2")
env.SetMethod "addAddress", "http://address.example.org/"
set adr = env.Parameters.Create ("address", empty)
adr.Nodes.Create "number", "100"
adr.Nodes.Create "street", "Spear Street"
adr.Nodes.Create "city",   "San Francisco"
adr.Nodes.Create "state",  "CA"
adr.Nodes.Create "zip",    "94107"
set ph = adr.Nodes.Create ("phone", empty)
ph.Nodes.Create "area", "415"
ph.Nodes.Create "exchange", "343"
ph.Nodes.Create "number", "3000"

wscript.echo env.serialize
</pre>

<BR><BR><BR>
<h3>Copyright</h3>
<p>Copyright &copy; Simon Fell, 2000-2004. All rights reserved.<br>

</BODY>
</HTML>
